﻿using System;
using UnityEngine;

namespace Studio
{
	// Token: 0x02000502 RID: 1282
	public class Sky : Singleton<Sky>
	{
		// Token: 0x170003CA RID: 970
		// (get) Token: 0x0600207C RID: 8316 RVA: 0x000C915C File Offset: 0x000C735C
		// (set) Token: 0x0600207D RID: 8317 RVA: 0x000C9164 File Offset: 0x000C7364
		public Camera cameraMain
		{
			get
			{
				return this._cameraMain;
			}
			private set
			{
				this._cameraMain = value;
			}
		}

		// Token: 0x170003CB RID: 971
		// (get) Token: 0x0600207E RID: 8318 RVA: 0x000C9170 File Offset: 0x000C7370
		// (set) Token: 0x0600207F RID: 8319 RVA: 0x000C9178 File Offset: 0x000C7378
		public Material matSky { get; private set; }

		// Token: 0x170003CC RID: 972
		// (get) Token: 0x06002080 RID: 8320 RVA: 0x000C9184 File Offset: 0x000C7384
		// (set) Token: 0x06002081 RID: 8321 RVA: 0x000C918C File Offset: 0x000C738C
		public Skybox skybox { get; private set; }

		// Token: 0x06002082 RID: 8322 RVA: 0x000C9198 File Offset: 0x000C7398
		public bool LoadSky(int _no)
		{
			this.ReleaseSky();
			Info.LoadCommonInfo loadCommonInfo = null;
			if (!Singleton<Info>.Instance.dicSkyLoadInfo.TryGetValue(_no, out loadCommonInfo))
			{
				return true;
			}
			this.matSky = CommonLib.LoadForceAsset<Material>(loadCommonInfo.bundlePath, loadCommonInfo.fileName, true, loadCommonInfo.manifest);
			if (this.matSky == null)
			{
				GlobalData.Debug_LogError(string.Format("读取失败: {0} : {1} : {2}", loadCommonInfo.manifest, loadCommonInfo.bundlePath, loadCommonInfo.fileName));
				return false;
			}
			this.skybox.material = this.matSky;
			this.cameraMain.clearFlags = CameraClearFlags.Skybox;
			return true;
		}

		// Token: 0x06002083 RID: 8323 RVA: 0x000C9238 File Offset: 0x000C7438
		public void ReleaseSky()
		{
			this.skybox.material = null;
			this.cameraMain.clearFlags = CameraClearFlags.Color;
			this.matSky = null;
		}

		// Token: 0x06002084 RID: 8324 RVA: 0x000C925C File Offset: 0x000C745C
		protected override void Awake()
		{
			if (!base.CheckInstance())
			{
				return;
			}
			UnityEngine.Object.DontDestroyOnLoad(base.gameObject);
			if (this._cameraMain == null)
			{
				this._cameraMain = Camera.main;
			}
			this.skybox = this._cameraMain.GetOrAddComponent<Skybox>();
		}

		// Token: 0x0400223B RID: 8763
		[SerializeField]
		private Camera _cameraMain;
	}
}
